package tv.youxing.android.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import tv.youxing.android.R;
import tv.youxing.android.entity.ViewPlayerPingLunModel;
import tv.youxing.android.utils.PicassoUtils;

/**
 * Created by Administrator on 2017/6/23.
 */

public class DynamicDetailsAdapter  extends BaseAdapter {
    Context mContext;
    List<ViewPlayerPingLunModel.ResultBean.DataBean> mPinglunListData = new ArrayList<>();//评论列表数据
    private LayoutInflater layoutInflater;


    public DynamicDetailsAdapter(Context context, List<ViewPlayerPingLunModel.ResultBean.DataBean> pinglunListData) {
        mContext = context;
        mPinglunListData = pinglunListData;
        this.layoutInflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
    }




    @Override
    public int getCount() {


        return this.mPinglunListData==null ? 0 : mPinglunListData.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Holder viewHolder = null;
        if (viewHolder==null) {
            viewHolder = new  Holder();
            convertView = layoutInflater.inflate(R.layout.video_player_item, null);
            viewHolder.iv_head = (ImageView) convertView.findViewById(R.id.ivIcon);
            viewHolder.tv_title = (TextView) convertView.findViewById(R.id.tvName);
            viewHolder.tv_time = (TextView) convertView.findViewById(R.id.tvTime);
            viewHolder.tv_content = (TextView) convertView.findViewById(R.id.tvContent);
            viewHolder.iv_dianzhan = (ImageView) convertView.findViewById(R.id.ivPraise);
            viewHolder.iv_vip = convertView.findViewById(R.id.icon_vip);
            convertView.setTag(viewHolder);
        }else{
            viewHolder = (Holder) convertView.getTag();
        }



//        PicassoUtils.loadImageView(mContext,mPinglunListData.get(position).getPublish_user().getAvatar(),viewHolder.iv_head);
        PicassoUtils.loadImageViewHolder(mContext,mPinglunListData.get(position).getPublish_user().getAvatar(),R.drawable.logo,R.drawable.logo,viewHolder.iv_head);
        viewHolder.tv_title.setText(mPinglunListData.get(position).getPublish_user().getUsername());
        viewHolder.tv_time.setText(mPinglunListData.get(position).getUpdated_at());
        viewHolder.tv_content.setText(mPinglunListData.get(position).getContent());


        System.out.println("--:"+viewHolder.tv_title);

        viewHolder.iv_dianzhan.setVisibility(View.GONE);
//        viewHolder.iv_dianzhan.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//
//            }
//        });

        if (mPinglunListData.get(position).getPublish_user().getIs_authenticated() == 1) {
            viewHolder.iv_vip.setVisibility(View.VISIBLE);
        } else {
            viewHolder.iv_vip.setVisibility(View.GONE);
        }

        return convertView;
    }


    class Holder {

        ImageView iv_head;
        TextView tv_title;//name
        TextView tv_time;
        TextView tv_content;
        ImageView iv_dianzhan;
        ImageView iv_vip;

    }
}
